package providerConsume;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

public class MainRun {
	
	
	public static void main(String[] args) {
		
		
		BlockingQueue<Data> blockingQueue = new LinkedBlockingQueue<>();
		
		Provider p1 = new Provider(blockingQueue);
		Provider p2 = new Provider(blockingQueue);
		Provider p3 = new Provider(blockingQueue);
		
		
		Consume c1 = new Consume(blockingQueue);
		Consume c2 = new Consume(blockingQueue);
		Consume c3 = new Consume(blockingQueue);
		
		//线程池
		ExecutorService cachePool = Executors.newCachedThreadPool(); 
			
		cachePool.execute(p1);
		cachePool.execute(p2);
		cachePool.execute(p3);
		
		cachePool.execute(c1);
		cachePool.execute(c2);
		cachePool.execute(c3);
		
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		p1.stop();
		p2.stop();
		p3.stop();
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}		
	}
	

}

